from llama_index.core import Settings
from llama_index.core.base.llms.types import MessageRole
from llama_index.llms.dashscope import DashScope, DashScopeGenerationModels
import os
from llama_index.core.llms import ChatMessage,MessageRole
os.environ["DASHSCOPE_API_KEY"] = "sk-f97e3654139742a4b01a99631628d36d"
dashscope_llm = DashScope(model_name=DashScopeGenerationModels.QWEN_MAX,api_key="sk-f97e3654139742a4b01a99631628d36d")
# res = dashscope_llm.complete("hello")
# print(res)

# res = dashscope_llm.stream_complete("你是谁，你可以帮我解决什么问题？")
# for r in res:
#     print(r.delta,end='\n')
msg = [ChatMessage(content="你是一个旅行家，擅长介绍每个城市的旅游景点",role=MessageRole.SYSTEM),
       ChatMessage(content="西安",role=MessageRole.USER)]
res = dashscope_llm.chat(msg)
print(res)
# from llama_index.embeddings.dashscope import (
#     DashScopeEmbedding,
#     DashScopeTextEmbeddingModels,
#     DashScopeTextEmbeddingType
# )
#
# #词嵌入模型
# embed_model = DashScopeEmbedding(
#     model_name=DashScopeTextEmbeddingModels.TEXT_EMBEDDING_V3,
#     text_type=DashScopeTextEmbeddingType.TEXT_TYPE_DOCUMENT,
#     api_key="sk-f97e3654139742a4b01a99631628d36d"
# )
#
# text = ["⻛急天⾼猿啸哀", "渚清沙⽩⻦⻜回", "⽆边落⽊萧萧下", "不尽⻓江滚滚来"]
# result_embeddings = embed_model.get_text_embedding_batch(text)
# for embedding in result_embeddings:
#     print(embedding)